<!-- 充值 -->
<template>
	<view>
		<u-navbar :isFixed="true" title="充值" :borderBottom="false"></u-navbar>
		<view class="block"></view>
		<view class="wrap">
			<view class="tips">请完善以下充值信息</view>
			<view class="charge flex_bet">
				<view class="name">
					<view>充值金额</view>
					<view class="balance">余额￥{{wallet}}</view>
				</view>
				<input type="digit" v-model="withdrawal_money" placeholder="请输入充值金额">
			</view>
			<view class="block"></view>
			<view class="title">选择充值方式</view>
			<view class="flex_bet_align type">
				<view>
					<u-icon name="weixin-circle-fill" color="#00C900" size="40"></u-icon>
					<text>微信</text>
				</view>
				<view class="iconfont icon-xuanzhong"></view>
			</view>
		</view>
		<view style="height:140rpx;"></view>
		<view class="btn" @click="submit">提交</view>
	</view>
</template>

<script>
	var _this;
	export default {
		data() {
			return {
				wallet:"",
				withdrawal_money:""
			}
		},
		onLoad(options) {
			_this = this
			_this.getdata()
		},
		methods: {
			// 获取数据
			getdata() {
				_this.$api.get("balance", {}).then(data => {
					_this.wallet = data
				});
			},
			// 提交
			submit() {
				_this.click_shake(function(){
					let data = [{
							value: _this.withdrawal_money,
							type: 1,
							title: "请填写充值金额"
						}
					]
					if (_this.$plug.verify(data)) {
						_this.$api.post("walletrecharge", {
							money: _this.withdrawal_money,
							pay_type:1,
							pay_tuneup_type: 1,
						}).then(data => {
							console.log(data,'xcx')
							uni.requestPayment({
								provider: 'wxpay',
								timeStamp: data.timeStamp,
								nonceStr: data.nonceStr,
								package: data.package,
								signType: data.signType,
								paySign: data.paySign,
								success: function (res) {
									wx.showModal({
										title: '提示',
										content: '充值成功',
										showCancel: false,
										success: function (res) {
											wx.navigateBack({
												delta: 1
											})
										}
									})
								},
								fail: function (res) {
									wx.showModal({
										title: '提示',
										content: '购买人数过多，等待一下再支付',
										showCancel: false
									})
								}
							});
						});
					}
				})
			},
			// 防抖点击
			click_shake(fn){
				if(!_this.shake){
					fn && typeof fn === 'function' && fn()
					_this.shake=true
					setTimeout(function(){
						_this.shake=false
					},500)
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	page{
		font-family: PingFang SC;
	}
	.block{
		height: 10rpx;
		background-color: #F2F2F2;
	}
	.wrap{
		padding:0 30rpx;
		.tips{
			font-size: 24rpx;
			color: #999999;
			line-height: 100rpx;
			border-bottom: 1rpx solid #EEEEEE;
		}
		.charge{
			padding:30rpx 0 40rpx;
			.name{
				font-size: 30rpx;
				text-align: left;
				color: #000000;
				.balance{
					font-size: 24rpx;
					color: #666666;
					margin-top:10rpx;
				}
			}
			input{
				width: 208rpx;
				font-size: 30rpx;
				text-align: right;
			}
		}
		.title{
			font-size: 26rpx;
			color: #666666;
			line-height: 100rpx;
		}
		.add{
			font-size: 26rpx;
			font-weight: 500;
			color: #333333;
			line-height: 100rpx;
		}
		.type{
			padding:32rpx 0;
			text{
				margin-left:20rpx;
			}
			.iconfont{
				color:#8E8E8E;
				font-size: 34rpx;
			}
			.icon-xuanzhong{
				color:#38BE8C;
			}
		}
	}
	.btn{
		width: 680rpx;
		height: 90rpx;
		background: linear-gradient(86deg,#38be8c 0%, #05adbb 100%);
		border-radius: 45rpx;
		font-size: 34rpx;
		font-weight: 700;
		text-align: center;
		color: #ffffff;
		line-height: 90rpx;
		position: fixed;
		left:28rpx;
		bottom:46rpx;
	}
</style>
